package com.shenzhen.horselive.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.annotation.NonNull;

import com.shenzhen.horselive.R;
import com.shenzhen.horselive.beans.UserAcountBean;
import com.shenzhen.horselive.databinding.DialogCancelYuyueBinding;

import java.text.NumberFormat;

public class DialogCaneclApply  extends Dialog {
    public DialogCaneclApply(@NonNull Context context) {
        super(context, R.style.CommonDialog);
        initViews();
    }


    public DialogCaneclApply(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }
    private OnButtonClick  onButtonClick;

    public void setOnButtonClick(OnButtonClick onButtonClick) {
        this.onButtonClick = onButtonClick;
    }

    DialogCancelYuyueBinding   binding;
    private void initViews() {
        binding= DialogCancelYuyueBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        binding.btQuit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        binding.btConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onButtonClick!=null)
                {
                    onButtonClick.onClick();
                }
                dismiss();
            }
        });

    }

    public void  setData(String money, UserAcountBean.DataBean  dataBean)
    {
        binding.tvMoney.setText("¥"+money);
        binding.tvPrice.setText("¥1/"+dataBean.getOneRatio()+"个");

        double  num = Double.parseDouble(money)/Double.parseDouble(dataBean.getRatio());
        NumberFormat  format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(10);
        binding.tvAmount.setText(format.format(num));

    }



    @Override
    public void show() {
        super.show();
        WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
        layoutParams.width= ViewGroup.LayoutParams.MATCH_PARENT;
        layoutParams.height= ViewGroup.LayoutParams.WRAP_CONTENT;
        layoutParams.gravity = Gravity.BOTTOM;
        getWindow().setAttributes(layoutParams);
    }





    public interface  OnButtonClick{
        void  onClick();
    }


}
